﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model_Layer;
using System.Data.SqlClient;

namespace Data_Access_Layer
{
    public class DBCustomer : IDBCustomer
    {
        private SqlConnection con;

        public DBCustomer()
        {
            con = Connection.GetInstance().GetConnection();
        }

        public void InsertCustomer(Customer cus)
        {
            getMaxId max = new getMaxId();
            int maxId = max.maxId("select MAX(personid) FROM Person");
            string query = "insert into Person values (" + maxId + "," + cus.Fname + "," + cus.Lname + "," + cus.Gender + "," + cus.Paddress + "," + cus.DateOfBirth + "," + cus.IsCusFlag + "," + cus.IsPassFlag + ")";
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();

            query ="insert into customer values (" + maxId + "," + cus.PhoneNo + "," + cus.Email + "," + cus.CreditCardInfo + ")";
            cmd = new SqlCommand(query, con);
        }

    }
}
